(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

f(0) → 1
f(s(x)) → g(x, s(x))
g(0, y) → y
g(s(x), y) → g(x, +(y, s(x)))
+(x, 0) → x
+(x, s(y)) → s(+(x, y))
g(s(x), y) → g(x, s(+(y, x)))

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

f(0) → 1 [1]
f(s(x)) → g(x, s(x)) [1]
g(0, y) → y [1]
g(s(x), y) → g(x, +(y, s(x))) [1]
+(x, 0) → x [1]
+(x, s(y)) → s(+(x, y)) [1]
g(s(x), y) → g(x, s(+(y, x))) [1]

Rewrite Strategy: INNERMOST

(3) CpxWeightedTrsRenamingProof (BOTH BOUNDS(ID, ID) transformation)

Renamed defined symbols to avoid conflicts with arithmetic symbols:

+ => plus

(4) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

f(0) → 1 [1]
f(s(x)) → g(x, s(x)) [1]
g(0, y) → y [1]
g(s(x), y) → g(x, plus(y, s(x))) [1]
plus(x, 0) → x [1]
plus(x, s(y)) → s(plus(x, y)) [1]
g(s(x), y) → g(x, s(plus(y, x))) [1]

Rewrite Strategy: INNERMOST

(5) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(6) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

f(0) → 1 [1]
f(s(x)) → g(x, s(x)) [1]
g(0, y) → y [1]
g(s(x), y) → g(x, plus(y, s(x))) [1]
plus(x, 0) → x [1]
plus(x, s(y)) → s(plus(x, y)) [1]
g(s(x), y) → g(x, s(plus(y, x))) [1]

The TRS has the following type information:
f :: 0:1:s → 0:1:s
0 :: 0:1:s
1 :: 0:1:s
s :: 0:1:s → 0:1:s
g :: 0:1:s → 0:1:s → 0:1:s
plus :: 0:1:s → 0:1:s → 0:1:s

Rewrite Strategy: INNERMOST

(7) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

f(v0) → null_f [0]
g(v0, v1) → null_g [0]
plus(v0, v1) → null_plus [0]

And the following fresh constants:

null_f, null_g, null_plus

(8) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

f(0) → 1 [1]
f(s(x)) → g(x, s(x)) [1]
g(0, y) → y [1]
g(s(x), y) → g(x, plus(y, s(x))) [1]
plus(x, 0) → x [1]
plus(x, s(y)) → s(plus(x, y)) [1]
g(s(x), y) → g(x, s(plus(y, x))) [1]
f(v0) → null_f [0]
g(v0, v1) → null_g [0]
plus(v0, v1) → null_plus [0]

The TRS has the following type information:
f :: 0:1:s:null_f:null_g:null_plus → 0:1:s:null_f:null_g:null_plus
0 :: 0:1:s:null_f:null_g:null_plus
1 :: 0:1:s:null_f:null_g:null_plus
s :: 0:1:s:null_f:null_g:null_plus → 0:1:s:null_f:null_g:null_plus
g :: 0:1:s:null_f:null_g:null_plus → 0:1:s:null_f:null_g:null_plus → 0:1:s:null_f:null_g:null_plus
plus :: 0:1:s:null_f:null_g:null_plus → 0:1:s:null_f:null_g:null_plus → 0:1:s:null_f:null_g:null_plus
null_f :: 0:1:s:null_f:null_g:null_plus
null_g :: 0:1:s:null_f:null_g:null_plus
null_plus :: 0:1:s:null_f:null_g:null_plus

Rewrite Strategy: INNERMOST

(9) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
1 => 1
null_f => 0
null_g => 0
null_plus => 0

(10) Obligation:

Complexity RNTS consisting of the following rules:

f(z) -{ 1 }→ g(x, 1 + x) :|: x >= 0, z = 1 + x
f(z) -{ 1 }→ 1 :|: z = 0
f(z) -{ 0 }→ 0 :|: v0 >= 0, z = v0
g(z, z') -{ 1 }→ y :|: y >= 0, z = 0, z' = y
g(z, z') -{ 1 }→ g(x, plus(y, 1 + x)) :|: x >= 0, y >= 0, z = 1 + x, z' = y
g(z, z') -{ 1 }→ g(x, 1 + plus(y, x)) :|: x >= 0, y >= 0, z = 1 + x, z' = y
g(z, z') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z = v0, z' = v1
plus(z, z') -{ 1 }→ x :|: x >= 0, z = x, z' = 0
plus(z, z') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z = v0, z' = v1
plus(z, z') -{ 1 }→ 1 + plus(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = x

Only complete derivations are relevant for the runtime complexity.

(11) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V2),0,[f(V, Out)],[V >= 0]).
eq(start(V, V2),0,[g(V, V2, Out)],[V >= 0,V2 >= 0]).
eq(start(V, V2),0,[plus(V, V2, Out)],[V >= 0,V2 >= 0]).
eq(f(V, Out),1,[],[Out = 1,V = 0]).
eq(f(V, Out),1,[g(V1, 1 + V1, Ret)],[Out = Ret,V1 >= 0,V = 1 + V1]).
eq(g(V, V2, Out),1,[],[Out = V3,V3 >= 0,V = 0,V2 = V3]).
eq(g(V, V2, Out),1,[plus(V5, 1 + V4, Ret1),g(V4, Ret1, Ret2)],[Out = Ret2,V4 >= 0,V5 >= 0,V = 1 + V4,V2 = V5]).
eq(plus(V, V2, Out),1,[],[Out = V6,V6 >= 0,V = V6,V2 = 0]).
eq(plus(V, V2, Out),1,[plus(V7, V8, Ret11)],[Out = 1 + Ret11,V2 = 1 + V8,V7 >= 0,V8 >= 0,V = V7]).
eq(g(V, V2, Out),1,[plus(V10, V9, Ret111),g(V9, 1 + Ret111, Ret3)],[Out = Ret3,V9 >= 0,V10 >= 0,V = 1 + V9,V2 = V10]).
eq(f(V, Out),0,[],[Out = 0,V11 >= 0,V = V11]).
eq(g(V, V2, Out),0,[],[Out = 0,V12 >= 0,V13 >= 0,V = V12,V2 = V13]).
eq(plus(V, V2, Out),0,[],[Out = 0,V14 >= 0,V15 >= 0,V = V14,V2 = V15]).
input_output_vars(f(V,Out),[V],[Out]).
input_output_vars(g(V,V2,Out),[V,V2],[Out]).
input_output_vars(plus(V,V2,Out),[V,V2],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [plus/3]
1. recursive : [g/3]
2. non_recursive : [f/2]
3. non_recursive : [start/2]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into plus/3
1. SCC is partially evaluated into g/3
2. SCC is partially evaluated into f/2
3. SCC is partially evaluated into start/2

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations plus/3
* CE 14 is refined into CE [15]
* CE 12 is refined into CE [16]
* CE 13 is refined into CE [17]


### Cost equations --> "Loop" of plus/3
* CEs [17] --> Loop 11
* CEs [15] --> Loop 12
* CEs [16] --> Loop 13

### Ranking functions of CR plus(V,V2,Out)
* RF of phase [11]: [V2]

#### Partial ranking functions of CR plus(V,V2,Out)
* Partial RF of phase [11]:
- RF of loop [11:1]:
V2


### Specialization of cost equations g/3
* CE 11 is refined into CE [18]
* CE 8 is refined into CE [19]
* CE 9 is refined into CE [20,21,22]
* CE 10 is refined into CE [23,24,25,26]


### Cost equations --> "Loop" of g/3
* CEs [22,24,26] --> Loop 14
* CEs [20] --> Loop 15
* CEs [21,23,25] --> Loop 16
* CEs [18] --> Loop 17
* CEs [19] --> Loop 18

### Ranking functions of CR g(V,V2,Out)
* RF of phase [14,15,16]: [V]

#### Partial ranking functions of CR g(V,V2,Out)
* Partial RF of phase [14,15,16]:
- RF of loop [14:1,15:1,16:1]:
V


### Specialization of cost equations f/2
* CE 6 is refined into CE [27,28,29]
* CE 7 is refined into CE [30]
* CE 5 is refined into CE [31]


### Cost equations --> "Loop" of f/2
* CEs [29] --> Loop 19
* CEs [28,30] --> Loop 20
* CEs [27] --> Loop 21
* CEs [31] --> Loop 22

### Ranking functions of CR f(V,Out)

#### Partial ranking functions of CR f(V,Out)


### Specialization of cost equations start/2
* CE 2 is refined into CE [32,33,34,35]
* CE 3 is refined into CE [36,37,38]
* CE 4 is refined into CE [39,40,41,42]


### Cost equations --> "Loop" of start/2
* CEs [39] --> Loop 23
* CEs [33] --> Loop 24
* CEs [32,34,35,36,37,38,40,41,42] --> Loop 25

### Ranking functions of CR start(V,V2)

#### Partial ranking functions of CR start(V,V2)


Computing Bounds
=====================================

#### Cost of chains of plus(V,V2,Out):
* Chain [[11],13]: 1*it(11)+1
Such that:it(11) =< V2

with precondition: [V+V2=Out,V>=0,V2>=1]

* Chain [[11],12]: 1*it(11)+0
Such that:it(11) =< Out

with precondition: [V>=0,Out>=1,V2>=Out]

* Chain [13]: 1
with precondition: [V2=0,V=Out,V>=0]

* Chain [12]: 0
with precondition: [Out=0,V>=0,V2>=0]


#### Cost of chains of g(V,V2,Out):
* Chain [[14,15,16],18]: 4*it(14)+2*s(9)+1*s(11)+1*s(12)+1
Such that:aux(7) =< V
it(14) =< aux(7)
aux(4) =< aux(7)-1
aux(3) =< aux(7)
s(10) =< it(14)*aux(7)
s(12) =< it(14)*aux(4)
s(11) =< it(14)*aux(3)
s(9) =< s(10)

with precondition: [V>=1,V2>=0,Out>=0]

* Chain [[14,15,16],17]: 4*it(14)+2*s(9)+1*s(11)+1*s(12)+0
Such that:aux(8) =< V
it(14) =< aux(8)
aux(4) =< aux(8)-1
aux(3) =< aux(8)
s(10) =< it(14)*aux(8)
s(12) =< it(14)*aux(4)
s(11) =< it(14)*aux(3)
s(9) =< s(10)

with precondition: [Out=0,V>=1,V2>=0]

* Chain [18]: 1
with precondition: [V=0,V2=Out,V2>=0]

* Chain [17]: 0
with precondition: [Out=0,V>=0,V2>=0]


#### Cost of chains of f(V,Out):
* Chain [22]: 1
with precondition: [V=0,Out=1]

* Chain [21]: 2
with precondition: [V=1,Out=1]

* Chain [20]: 4*s(22)+1*s(26)+1*s(27)+2*s(28)+1
Such that:s(21) =< V
s(22) =< s(21)
s(23) =< s(21)-1
s(24) =< s(21)
s(25) =< s(22)*s(21)
s(26) =< s(22)*s(23)
s(27) =< s(22)*s(24)
s(28) =< s(25)

with precondition: [Out=0,V>=0]

* Chain [19]: 4*s(30)+1*s(34)+1*s(35)+2*s(36)+2
Such that:s(29) =< V
s(30) =< s(29)
s(31) =< s(29)-1
s(32) =< s(29)
s(33) =< s(30)*s(29)
s(34) =< s(30)*s(31)
s(35) =< s(30)*s(32)
s(36) =< s(33)

with precondition: [V>=2,Out>=0]


#### Cost of chains of start(V,V2):
* Chain [25]: 16*s(38)+4*s(42)+4*s(43)+8*s(44)+2*s(69)+2
Such that:aux(9) =< V
aux(10) =< V2
s(69) =< aux(10)
s(38) =< aux(9)
s(39) =< aux(9)-1
s(40) =< aux(9)
s(41) =< s(38)*aux(9)
s(42) =< s(38)*s(39)
s(43) =< s(38)*s(40)
s(44) =< s(41)

with precondition: [V>=0]

* Chain [24]: 2
with precondition: [V=1]

* Chain [23]: 1
with precondition: [V2=0,V>=0]


Closed-form bounds of start(V,V2):
-------------------------------------
* Chain [25] with precondition: [V>=0]
- Upper bound: 16*V+2+12*V*V+nat(V2)*2+nat(V-1)*4*V
- Complexity: n^2
* Chain [24] with precondition: [V=1]
- Upper bound: 2
- Complexity: constant
* Chain [23] with precondition: [V2=0,V>=0]
- Upper bound: 1
- Complexity: constant

### Maximum cost of start(V,V2): max([1,16*V+1+12*V*V+nat(V2)*2+nat(V-1)*4*V])+1
Asymptotic class: n^2
* Total analysis performed in 220 ms.

(12) BOUNDS(1, n^2)